package com.su.gulimall.product.web;

import com.su.gulimall.product.entity.CategoryEntity;
import com.su.gulimall.product.service.CategoryService;
import com.su.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;
    @GetMapping({"/","index.html"})
    public  String  indexPage(Model model)
    {
        List<CategoryEntity>  categoryEntityList=categoryService.getLevel1Categorys();
        //视图解析器进行配置，前面是/templates/+返回值+html
        model.addAttribute("categorys",categoryEntityList);
     // TODO 动态查出来所有的数据并进行显示
     return "index";
    }
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatalogJson()
    {
        Map<String, List<Catelog2Vo>> catalogJson =categoryService.getCatalogJson();
        return catalogJson;
    }


}
